<!-- 关注和粉丝 -->
<template>
	<view>
		<view class="item" v-for="(item,index) in data" :key="index">
			<view class="left">
				<view class="img">
					<image :src="item.avatarUrl"></image>
					<image v-if="item.avatarDetail.identityIconUrl" :src="item.avatarDetail.identityIconUrl"></image>
				</view>
				<view class="content">
					<text>{{item.nickname}}</text>
					<text>{{item.signature}}</text>
				</view>
				<view class="follow" v-if="title==='我的粉丝'">
					<text>+ 回关</text>
				</view>
			</view>
			<view class="right" @click="delfollow(item.userId)">
				<image src="../../static/follow/更多.png"></image>
			</view>
		</view>
		<view class="bottom" v-show="isshow">
			<template v-if="title==='我的关注'">
				<view>
					<text>取消关注后对方将从你的关注列表中移除</text>
				</view>
				<view @click="follow">
					<image src="../../static/follow/取消关注.png"></image>
					<text>取消关注</text>
				</view>
			</template>
			<template v-else>
				<view>
					<text>移除粉丝之后你将从对方的关注列表中删除</text>
				</view>
				<view>
					<image src="../../static/follow/删除.png"></image>
					<text>移除粉丝</text>
				</view>
			</template>
		</view>
	</view>
</template>

<script>
	import {
		mapActions,
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				isshow: false, // 表示取消关注的模态框是否显示
				title: '', // 表示当前显示的页面标题
				userId: -1, // 当前点击的用户
			};
		},
		onLoad(data) {
			let type = data['type'] // 区分当前页面是关注还是请求
			let id = uni.getStorageSync('UserInfoNid')
			// 如果用户id不存在，则直径跳转到登录页面
			if (!id) {
				uni.redirectTo({
					url: '/pages/login/login'
				})
				uni.showToast({
					title: '请先登录',
					icon: 'none'
				})
				return
			}
			if (type === 'follows') {
				this.GetFollows(id)
				this.title = '我的关注'
			} else if (type === 'followeds') {
				this.Getfolloweds(id)
				this.title = '我的粉丝'
			}
			uni.setNavigationBarTitle({
				title: this.title
			})
		},
		methods: {
			...mapActions('follow', ['GetFollows', 'Getfolloweds', 'Follow']),
			...mapMutations('follow', ['setdata']),

			// 显示取消关注、删除粉丝回调
			delfollow(userId) {
				this.isshow = !this.isshow
				this.userId = userId
			},

			// 取消关注回调
			follow() {
				this.Follow({
					id: this.userId,
					t: 0
				})
			}
		},
		computed: {
			...mapState('follow', ['data'])
		},
		onUnload() {
			// 清空数据
			this.setdata([])
		}
	}
</script>

<style lang="scss">
	page {
		padding: 30rpx 0 0 0;
	}

	.item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 100rpx;
		margin-bottom: 30rpx;
		padding-left: 30rpx;

		.left {
			display: flex;
			align-items: center;

			.img {
				position: relative;
				height: 100rpx;
				width: 100rpx;
				margin-right: 30rpx;

				image {
					border-radius: 50%;
				}

				& image:nth-child(1) {
					height: 100rpx;
					width: 100rpx;
				}

				& image:nth-child(2) {
					height: 35rpx;
					width: 35rpx;
					position: absolute;
					bottom: 0;
					right: 10rpx;
				}
			}

			.content {
				display: flex;
				flex-direction: column;
				justify-content: center;
				line-height: 40rpx;

				& text:nth-child(1) {
					font-size: 28rpx;
					opacity: 0.8;
				}

				& text:nth-child(2) {
					font-size: 25rpx;
					opacity: 0.6;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 1;
					-webkit-box-orient: vertical;
					width: 350rpx;
				}
			}

			.follow {
				border: 2rpx #c20c0c solid;
				border-radius: 30rpx;
				height: 50rpx;
				width: 100rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-left: 10rpx;

				text {
					font-size: 22rpx;
					opacity: 0.8;
				}
			}
		}

		.right {
			height: 100%;
			width: 50rpx;
			display: flex;
			align-items: center;

			image {
				height: 30rpx;
				width: 30rpx;
			}
		}
	}

	.bottom {
		position: fixed;
		bottom: 0;
		height: 200rpx;
		background-color: #1c1c1e;
		width: 100%;
		border-radius: 30rpx 30rpx 0 0;

		& view:nth-child(1) {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			opacity: 0.8;
			height: 40%;
			padding-left: 30rpx;
		}

		& view:nth-child(2) {
			height: 60%;
			display: flex;
			align-items: center;
			padding-left: 30rpx;

			image {
				height: 45rpx;
				width: 45rpx;
				margin-right: 30rpx;
			}

			text {
				font-size: 28rpx;
			}
		}
	}
</style>
